package com.cenxi.controller;

import com.cx.minio.utils.MinioUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author cenxi
 * @Date 2023/10/18 15:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/minio")
public class MinioController {
    @Resource
    private MinioUtils minioUtils;

    /**
     * 上传文件
     * @param file 文件
     * @return 路径
     */
    @PostMapping("/upload")
    public Object uploadByMinio(@RequestPart(name = "file") MultipartFile file) {
        //返回存储路径
        return minioUtils.uploadFile(file, "cenxi");
    }

    @GetMapping("/download")
    public Object download(@RequestParam("fileName") String fileName, @RequestParam("bucketName") String bucketName, HttpServletResponse httpServletResponse) {
        //返回存储路径
        System.out.println("测试");
        minioUtils.fileDownload(fileName, bucketName, httpServletResponse);
        return "成功";
    }


}

